<?php 
namespace app\admin\service;


use app\admin\model\UserGetNpc;
use think\facade\Db;

/**
 * 用户兑换npc记录管理-服务类
 * @author 小树林
 * @since: 2024/11/22
 * Class UserGetNpcService
 * @package app\admin\service
 */
class UserGetNpcService extends BaseService
{
    /**
     * 构造函数
     * LevelService constructor.
     */
    public function __construct()
    {
        $this->model = new UserGetNpc();
    }
	
	/**
     * 获取数据列表
     * @return array
     * @since 2024/11/22
     * @author 小树林
     */
    public function getList()
    {
        $param = request()->param();

        //是否为远程搜索查询
        $is_query = $param['_is_query'] ?? '';
        if(!empty($is_query)){
            return parent::query($param);
        }

        // 查询条件
        $map = [];

        $nickname = getter($param,'nickname');
        if ($nickname) {
            $arr = Db::name("member")->where("nickname","like","%{$nickname}%")->column("id");
            $map[] = ['user_id', 'in', $arr];
        }

        $shopManager = getter($param,'shopManager');
        if ($shopManager) {
            $arr = Db::name("shop_manager")->alias("s")->leftJoin("evt_member m","m.id=s.user_id")->where("m.nickname","like","%{$shopManager}%")->column("s.id");
            $map[] = ['shop_manager_id', 'in', $arr];
        }
        $field = '*';
        $with = [
            'with',
            [
                'member'=>function($query){
                    $query->field('id,nickname');
                }
            ]
        ];
        $sort = '';

        $res = parent::getList($map,$field,$with,$sort); // TODO: Change the autogenerated stub
        if($res['count'] != 0){
            foreach($res['data'] as &$v) {
                $v['shopManager'] = Db::name("shop_manager")->alias("s")->leftJoin("evt_member m","m.id=s.user_id")->where("s.id",$v['shop_manager_id'])->value("m.nickname");
            }
        }
        return $res;
    }


                                                
}